<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="isCol12 ? 12 : 6" :sm="12">
                        <el-form-item label="直播间:" prop="roomId.value">
                            <SelectPage v-model="queryParams.roomId.value" placeholder="请选择直播间"
                                        :url="'/admin/live.room/selectPage'" show_field="roomName" show_id="id" query_field="id" :multiple="false" />
                        </el-form-item>

                    </el-col>
                    <el-col :md="isCol12 ? 12 : 6" :sm="12">
                        <el-form-item label="赠送用户:" prop="user_id.value">
                            <SelectPage v-model="queryParams.user_id.value" placeholder="请选择赠送用户"
                                        :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                        </el-form-item>

                    </el-col>
                    <el-col :md="isCol12 ? 12 : 6" :sm="12">
                        <el-form-item label="接收用户:" prop="target_user_id.value">
                            <SelectPage v-model="queryParams.target_user_id.value" placeholder="请选择接收用户"
                                        :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="isCol12 ? 12 : 6" :sm="12" v-if="!queryObj.gift_id">
                        <el-form-item label="礼物标题:" prop="gift_title.value">
                            <el-input v-model="queryParams.gift_title.value" placeholder="请输入礼物标题" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5" v-if="false">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5" v-if="false">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="80" v-if="!isCol12">
                        <template slot-scope="scope">
<!--                            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button>-->
                            <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
<!--                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>-->
                        </template>
                    </el-table-column>
                </template>
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? ( findFormData[pk] ? '编辑' : '添加' ) : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close append-to-body>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    props: {
        queryObj: {
            type: Object,
            default: ()=> {
                return {
                    gift_id: '',
                    roomId: ''
                }
            }
        }
    },
    data() {
        return {
            pk:'id',
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                    width: 60
                },
                {
                    visible: true,
                    label: '直播间',
                    prop: 'liveRoom.roomName',
                    width: 90,
                    overflow: true
                },
                {
                    visible: true,
                    label: '赠送用户',
                    prop: 'myUser.nickname',
                    width: 90,
                    overflow: true
                },
                {
                    visible: true,
                    label: '接收用户',
                    prop: 'targetUser.nickname',
                    width: 90,
                    overflow: true
                },
                {
                    visible: true,
                    label: '赠送数量',
                    prop: 'number',
                    width: 90,
                    overflow: true
                },
                {
                    visible: true,
                    label: '礼物标题',
                    prop: 'gift_title',
                },
                {
                    visible: true,
                    label: '礼物图片',
                    prop: 'gift_image',
                    component:'QuickAdminImage',
                    width: 90,
                    overflow: true
                },
                {
                    visible: true,
                    label: '礼物价值',
                    prop: 'gift_coin',
                    width: 90,
                    overflow: true
                },
                {
                    visible: true,
                    label: '收益价值',
                    prop: 'income_money',
                    width: 90,
                    overflow: true
                },
                {
                    visible: true,
                    label: '收益比例（%）',
                    prop: 'income_rate',
                    width: 120,
                    overflow: true
                },
                {
                    visible: true,
                    label: '创建时间',
                    prop: 'create_time',
                },
                {
                    visible: true,
                    label: '更新时间',
                    prop: 'update_time',
                }
            ],
            // 接口地址
            api: {
                index: `/admin/live.gift_log/index`,
                find: `/admin/live.gift_log/find`,
                add: `/admin/live.gift_log/add`,
                edit: `/admin/live.gift_log/edit`,
                delete: `/admin/live.gift_log/delete`,
                export: `/admin/live.gift_log/export`,
                status: `/admin/live.gift_log/status`
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                roomId: { value:undefined, op: '='},
                user_id: { value:undefined, op: '='},
                target_user_id: { value:undefined, op: '='},
                gift_id: { value:undefined, op: '='},
                gift_title: { value:undefined, op: '%like%'},
            },
            tableIsJoinLoad: false
        }
    },
    computed: {
        isCol12() {
            return this.queryObj.gift_id || this.queryObj.roomId
        }
    },
    created() {
        if (this.queryObj.gift_id) {
            this.queryParams.gift_id.value = this.queryObj.gift_id
            this.columns[5].visible = false
            this.columns[6].visible = false
            this.columns[7].visible = false
        }
        if (this.queryObj.roomId) {
            this.queryParams.roomId.value = this.queryObj.roomId
            this.columns[1].visible = false
        }
        this.initIndex()
    }
}
</script>
